package com.kikt.eventbustest;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;

public class MainActivity extends AppCompatActivity {

    @Bind(R.id.bt1)
    Button mBt1;
    @Bind(R.id.tv)
    TextView mTv;
    protected User user;

    @OnClick(R.id.bt_start)
    public void start(View view) {
        startActivity(new Intent(this,SecondActivity.class));
    }

    @OnClick(R.id.bt1)
    public void onClick(View view) {
        Toast.makeText(this, user.toString(), Toast.LENGTH_SHORT).show();

        mTv.setText(user.toString());
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        initData();

        PostEvent event = new PostEvent();
        event.user = user;

        EventBus.getDefault().postSticky(event);
    }

    private void initData() {
        user = new User();
        user.id = "11111";
        user.name = "11111";
    }
}
